﻿using Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DormMS.IService;
using DormMS.Model.Enum;

namespace WeChat.Controllers
{
    public class CouponController : BaseController
    {
        private ICouponService _couponService;
        private ICarouselService _carouselService;
        public CouponController(IMemberService s, ICouponService couponService, ICarouselService carouselService) : base(s)
        {
            _couponService = couponService;
            _carouselService = carouselService;
        }
        public ActionResult Index()
        {
            return View();
        }

        public JsonResult GetCouponList()
        {
            Result result = new Result();
            try
            {
                result.data = _couponService.GetCouponList();
                result.isSuccess = true;
            }
            catch (Exception ex)
            {

                result.msg=ex.Message;
            }

            return Json(result);
        }

        public JsonResult GetCarouselList()
        {
            Result result = new Result();
            try
            {
                result.data = _carouselService.GetCarousel((int)CarouselTypeEnum.优惠券领取页);
                result.isSuccess = true;
            }
            catch (Exception ex)
            {

                result.msg = ex.Message;
            }

            return Json(result);
        }

        public JsonResult ReceiveCoupon(int couponId)
        {
            Result result = new Result();
            try
            {
                _couponService.ReceiveCoupon(couponId, CurrentLoginUser.Id);
                result.isSuccess = true;
            }
            catch (Exception ex)
            {

                result.msg = ex.Message;
            }

            return Json(result);
        }

    }
}